package punctuatedEquilibrium;

import java.util.LinkedList;
import java.util.List;

public class DataCollector {

	private List<Double[]>	evolvedTraitsData;
	private Phenotype		phenotype;
	private Population		population;
	private List<Double[]>	selectivePressureData;

	public DataCollector(Population population, Phenotype inputPhenotype) {
		this.population = population;
		phenotype = inputPhenotype;
		selectivePressureData = new LinkedList<Double[]>();
		evolvedTraitsData = new LinkedList<Double[]>();
	}

	public void collectData() {
		Double[] selectivePressureDataPoint = phenotype.getArrayOfVariables();
		selectivePressureData.add(selectivePressureDataPoint);
		Double[] evolvedTraitsDataPoint = population.reportAverageTraits()
				.getArrayOfVariables();
		evolvedTraitsData.add(evolvedTraitsDataPoint);
	}

	public double[][] reportDataArray() {
		int dataLength = selectivePressureData.size();
		int combinedDataPointLength = selectivePressureData.get(0).length
				+ evolvedTraitsData.get(0).length;
		double[][] dataArray = new double[dataLength][combinedDataPointLength];
		for (int i = 0; i < dataLength; i++) {
			Double[] selectivePressureDataPoint = selectivePressureData.get(i);
			for (int j = 0; j < selectivePressureDataPoint.length; j++) {
				dataArray[i][j] = selectivePressureDataPoint[j];
			}
			Double[] evolvedTraitsDataPoint = evolvedTraitsData.get(i);
			for (int j = 0; j < evolvedTraitsDataPoint.length; j++) {
				dataArray[i][j + selectivePressureDataPoint.length] = evolvedTraitsDataPoint[j];
			}
		}
		return dataArray;
	}

}
